
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.CellEditEvent;
import org.primefaces.event.SlideEndEvent;

import domain.Alunno;
import domain.Car;
import domain.Giudizio;



@ManagedBean
@ViewScoped
public class TableBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


    private List<Giudizio> giudizioList;


	public TableBean() {

		giudizioList = new ArrayList<Giudizio>();

		populateRandomGiudizi(giudizioList, 9);
	}

	private void populateRandomGiudizi(List<Giudizio> list, int size) {
		for(int i = 0 ; i < size ; i++) {
			Giudizio giud = new Giudizio(getRandomVoto());
			Alunno al = new Alunno();
			al.setNome("alunno n." + i);
			giud.setAlunno(al);
			list.add(giud);
		}
	}


	public List<Giudizio> getGiudizioList() {
		return giudizioList;
	}


	private double getRandomVoto() {
		return (Math.random() * 10);
	}


    


    public void onCellEdit(CellEditEvent event) {
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        
        if(newValue != null && !newValue.equals(oldValue)) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }
    
    public void onSlideChange(SlideEndEvent event) {  
        FacesMessage msg = new FacesMessage("Slide hanged", "Value: " + event.getValue());  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  
}
                     